-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Miri: non-deterministic floating point operations in foreign_items
#143906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Miri: non-deterministic floating point operations in foreign_items
#143906
Conversation
The Miri subtree was changed cc @rust-lang/miri |
There are some holes in the behaviour of some operations, because I did not know how I could efficiently handle them, I'll mark them and add some explanation. Also, |
Please create a PR for the libstd changes on their own so a libs reviewer can review it. Once that is done and synced, you can open a PR against the miri repo with the miri changes. |
In a previous PR we had both in one PR with two reviewers since we needed to go back and forth a bit. We could do that again? I think it worked well.
|
It's the same for me, I kept the commits for Miri and stdlib separate, so if I have to split it up, it's pretty straightforward. |
🤷 I'm also fine either way, it'll just be a bunch of work to port the commits to the Miri repo.
Functions where C does not give an output range shouldn't get their value clamped, I would say. |
Please don't, that file is already too big.^^ If the helpers are only needed in one file, keep them there. |
Reopening. |
You're right, but this has some consequences. For example, the The C standard for the return values of
The range of sine x is [-1, 1], but is not explicitly defined. But
I think we have 2 approaches:
|
If we run into libm implementations that can't even guarantee to return a value within the math function's output domain, tbh I would consider that downright broken and worthy of a bug report, or strong reason to just always use our If it's mostly a concern about following the specification to the letter, I think it might be worth a defect report to see if the C committee is willing to codeify the output domain. |
I would suggest a third:
|
The arcsin function likely states this not as a means of guaranteeing precision, but because the inverse sine of |
I emailed a possible defect report to some of the (I think?) relevant contacts at https://www.open-std.org/jtc1/sc22/wg14/www/contacts and copied you both. |
@RalfJung If I want to fix that conflict I should rebase with --keep-base right? |
You need to fetch the latest |
Ah yeah, right, I mixed this with something else I did wrong in another pr. Thanks! |
ba2275c
to
af8f7c3
Compare
The last 3 commits are what changed since your review, Ralf. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This largely LGTM from the Miri side, though I do have a few comments.
@tgross35 could you take a look at the library side?
src/tools/miri/src/math.rs
Outdated
Self::from_u128(3).value | ||
} | ||
|
||
/// Equal PI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the comment say that's not already in the function name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing... I'l remove it :)
The test changes LGTM 👍 |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
That looks good. :) Please clean up the history, then this is good to go. |
What do you consider clean here? I guess that you don't want everything squashed to 1 commit. Would you like the changes to miri in 1 commit and changes to libstd in another one? |
Ideally there's three commits:
|
I'll try :). |
55f1f45
to
8978073
Compare
I think I did this correctly. @rustbot ready. |
You did unfortunately rebase over the latest master, that makes my life a bit harder now. :/ I thought I didn't have to repeat every single time to please use |
Looking good though, thanks! |
🤦 fuck, yeah, I'm sorry... |
Part of rust-lang/miri/#3555, this pr does the
foreign_items
work.Some things have changed since #138062 and #142514. I moved the "helpers" used for creating fixed outputs and clamping operations to their defined ranges to
helpers.rs
. These are now also extended to handle the floating-point operations inforeign_items
. Tests inmiri/tests/float.rs
were changed/added.Failing tests in
std
were extracted, run under miri with-Zmiri-many-seeds=0..1000
and changed accordingly. Double checked with-Zmiri-many-seeds
.I noticed that the C standard doesn't specify the output ranges for all of its mathematical operations; it just specifies them as:
So I used Wolfram|Alpha.